package com.pratices.redis.jedis.demo1;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.pratices.redis.jedis.bean.User;
import redis.clients.jedis.Jedis;

public class InstanceSavaApplication {
    public static void main(String[] args) throws JsonProcessingException {
        User user = User.builder()
                .username("zhangsan")
                .password("123456")
                .email("zhangsan@163.com")
                .phone("123456789")
                .build();

        ObjectMapper objectMapper = new ObjectMapper();
        String jsonStr = objectMapper.writeValueAsString(user);

        Jedis jedis = new Jedis("localhost", 6379);
//        jedis.set("user", jsonStr);

        String string = jedis.get("user");
        System.out.println(string);
        User user1 = objectMapper.readValue(string, User.class);
        System.out.println(user1);
    }
}
